<?php
require_once 'application/models/AbstractModel.php';
require_once 'application/models/MenuPrincipal.php';

class Menu extends AbstractModel
{
    protected $_name = 'Menu';
    
    protected $_dependentTables = array('MenuPrincipal');

    function __construct() {
        parent::__construct();
    	$this->_fieldsToDisplay = array('id', 'nom');
    }
   
    function getObjectFromRow($row) {
    	$object = $this->getArrayFromRow($row);
    	
	    $tableMP = new MenuPrincipal();
		
		$select = $this->select()->order('sort_order ASC');
	    $mPRows = $row->findDependentRowset('MenuPrincipal', 'Menu', $select);
	    
	    $mpList = array();
	    foreach ($mPRows as $mPRow) {
	    	$mpList[] = $tableMP->getObjectFromRow($mPRow);
	    }
	    $object['menu'] = $mpList;
  		    
	    return $object;
    }
}
    	